package com.infomanage.util;

import java.util.Hashtable;
import java.util.List;

import com.infomanage.dao.DeptDAO;
import com.infomanage.exception.DaoException;
import com.infomanage.po.Department;
import com.jiuqi.webtree.TreeNode;
import com.jiuqi.webtree.TreeNodeList;
import com.jiuqi.webtree.WebTreeInfo;
import com.jiuqi.webtree.WebTreeIntf;

public class DeptTree implements WebTreeIntf{
	private DeptDAO deptDAO = null;
	public DeptTree(){
		deptDAO = new DeptDAO();
	}

	public boolean delNode(String arg0, boolean arg1, String arg2) {
		// TODO Auto-generated method stub
		return false;
	}

	public String getErrorMessage() {
		// TODO Auto-generated method stub
		return null;
	}

	public String[] getNodePaths(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public TreeNodeList getNodes(String parentId, int arg1, WebTreeInfo arg2) {
		TreeNodeList childNodes = new TreeNodeList(1, 1);
		try {
			if(parentId == null || parentId.equals("")){
				parentId = "-1";
			}
			List<Department> list = deptDAO.findChildren(Integer.parseInt(parentId));
			for(Department dept : list){
				TreeNode treeNode = new TreeNode(String.valueOf(dept.getDeptId()), dept.getName(), true, null, false);
				Hashtable<String, String> attribtes = new Hashtable<String, String>();
				attribtes.put("fullTitle", dept.getPath());
				attribtes.put("hasExtend", "true");
				attribtes.put("deptLevel", String.valueOf(dept.getLevel()));
				treeNode.setAttributes(attribtes);
				childNodes.addNode(treeNode);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (DaoException e) {
			e.printStackTrace();
		}
		return childNodes;
	}

	public boolean insertNode(String arg0, String arg1, Hashtable arg2) {
		// TODO Auto-generated method stub
		return false;
	}

}
